<?php
/**
 * MoneyModel.class.php
 * 现金模型
 * 
 * @author  王中艺 <wangzy_smile@qq.com>
 * @date    2017-08-28
 */

namespace Common\Model;

class MoneyModel extends BaseModel {

    protected $trueTableName = 't_money';
    protected $cache    = false;

    const GOODS_TYPE_MAP  = [
        1   => '课程购买',
        2   => '用户问答',
        3   => '用户提现',
        4   => '购物车',
        5   => 'VIP购买'
    ];

    /**
     * 条目获取
     * @param   $condition
     * @return  $info
     */
    function getItem($condition){
        $where  = $this->setCondition($condition, 'a');
        $info   = $this->table('t_money a')
            ->join('left join t_user b on a.user_id = b.id')
            ->join('left join t_coupon_code c on a.code_id = c.id')
            ->where($where)
            ->field('a.*, b.nickname, b.truename, c.code, c.amount code_amount')
            ->find();
        $info['creat_date'] = date('Y-m-d H:i:s', $info['create_date']);

        return $info;
    }
    
    /**
     * 获取分成信息
     * @param   $id
     * @return  $info
     */
    function getDeductList($id){
        $deductList     = D('Deduct')->table('t_deduct a')
            ->join('left join t_user b on a.user_id = b.id')
            ->where('a.money_id = %d', $id)
            ->cache(true)
            ->field('a.*, b.truename, b.nickname, b.role_id')
            ->select();
        return D('Deduct')::resolveColumn($deductList, true);
    }
}